package com.example.monitoringsystem.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.monitoringsystem.bean.Doctor;
import com.example.monitoringsystem.bean.DoctorWorkTime;
import com.example.monitoringsystem.currentUser.StaticUser;
import com.example.monitoringsystem.mapper.DoctorWorkTimeMapper;
import com.example.monitoringsystem.service.DoctorWorkTimeService;
import com.example.monitoringsystem.service.HealthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.configurationprocessor.json.JSONArray;
import org.springframework.boot.configurationprocessor.json.JSONException;
import org.springframework.boot.configurationprocessor.json.JSONObject;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;


@RestController
public class DoctorWorkTimeController {
    @Autowired
    private DoctorWorkTimeService doctorWorkTimeService;

    @Autowired
    private DoctorWorkTimeMapper doctorWorkTimeMapper;

    // 根据医生id来获取医生的工作时间
//    @RequestMapping("/doctor/getWorkTime")
//    @ResponseBody
//    public String getWorkTime(@RequestParam("doctorId") Integer doctorId){
//        return doctorWorkTimeService.getWorkTimeByDoctorId(doctorId);
//    }

    // 根据医生id来获取医生的工作时间
    @RequestMapping("/doctor/getWorkTime")
    @ResponseBody
    public DoctorWorkTime getWorkTime(@RequestParam("doctorId") Integer doctorId){
        doctorId = StaticUser.getCurrentUser().getId();
        return doctorWorkTimeMapper.selectOne(new QueryWrapper<DoctorWorkTime>().eq("doctor_id",doctorId));
    }

    // 根据医生id来更新医生的工作时间
    @RequestMapping("/doctor/updateWorkTime")
    public void updateWorkTime(@RequestParam("doctorId") Integer doctorId,@RequestParam("workTime") String workTime){
        doctorWorkTimeService.updateWorkTimeByDoctorId(new DoctorWorkTime(doctorId,workTime));
    }

    // 获取全部医生的工作时间
    @RequestMapping("/doctor/getAllWorkTimes")
    @ResponseBody
    public List<DoctorWorkTime> getAllWorkTimes(){
        List<DoctorWorkTime> doctorWorkTimes = doctorWorkTimeService.getAllDoctorWorkTime();
        return doctorWorkTimes;
    }

    // 获取全部医生的工作时间
//    @RequestMapping("/doctor/getAllWorkTimes")
//    public HashMap<Integer,String> getAllWorkTimes(){
//        List<DoctorWorkTime> doctorWorkTimes = doctorWorkTimeService.getAllDoctorWorkTime();
//        HashMap<Integer,String> hashMap = new HashMap<>();
//        for(DoctorWorkTime doctorWorkTime:doctorWorkTimes){
//            hashMap.put(doctorWorkTime.getDoctorId(),doctorWorkTime.getWorkTime());
//        }
//        return hashMap;
//    }

    // 获取全部医生的工作时间
//    @RequestMapping("/doctor/getAllWorkTimes")
//    public String getAllWorkTimes(){
//        List<DoctorWorkTime> doctorWorkTimes = doctorWorkTimeService.getAllDoctorWorkTime();
////        HashMap<Integer,String> hashMap = new HashMap<>();
////        for(DoctorWorkTime doctorWorkTime:doctorWorkTimes){
////            hashMap.put(doctorWorkTime.getDoctorId(),doctorWorkTime.getWorkTime());
////        }
//        return doctorWorkTimes.toString();
//    }

    // 获取全部医生的工作时间
//    @RequestMapping("/doctor/getAllWorkTimes")
//    public JSONArray getAllWorkTimes(){
//        List<DoctorWorkTime> doctorWorkTimes = doctorWorkTimeService.getAllDoctorWorkTime();
//        JSONArray jsonArray = new JSONArray(doctorWorkTimes);
//        return jsonArray;
//    }
//    @RequestMapping("/doctor/getAllWorkTimes")
//    public JSONObject getAllWorkTimes() throws JSONException {
//        List<DoctorWorkTime> doctorWorkTimes = doctorWorkTimeService.getAllDoctorWorkTime();
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("doctorWorkTimes",doctorWorkTimes);
//        return jsonObject;
//    }
}
